import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:lcapp/api/interface/popover.dart';
import 'package:lcapp/api/request/response_data.dart';
import 'package:lcapp/data/popover_data_entity.dart';
import 'package:lcapp/model/popover/popmenuDialog.dart';

class PopoverManager {
  static List<PopoverDataEntity> pops = [];
  static bool isFinish = true;

  static Future<void> getPops() async {
    if(!isFinish){
      return;
    }
    isFinish = false;
    pops.clear();
    ResponseData res = await PopoverAPI.getPopoverList(
        {
          'page':1,
          'size':1
        }
    );
    if (res.code == 200) {
      List arr = res.data ??[];
      for (var element in arr) {
        PopoverDataEntity entity = PopoverDataEntity().fromJson(element);
        pops.add(entity);
      }
    }
    if(pops.isNotEmpty){
      Future.delayed(
        const Duration(milliseconds: 500),
            () {
          isFinish = true;
          SmartDialog.show(
            alignment: Alignment.center,
            clickMaskDismiss: false,
            maskColor: const Color.fromRGBO(0, 0, 0, 0.75),
             builder: (BuildContext context) {
              return PopMenuDialog(entity: pops[0]);
          },
          );
        },
      );
    }else{
      isFinish = true;
    }
  }

}